<?php

namespace App\Http\Resources;

use App\Helpers\BooksTrait;
use App\Models\Class\ChapterUnlock;
use App\Models\User;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;

class ClassMiniCollection extends JsonResource
{
    use BooksTrait;
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        // 'id','title','is_use_custom','cover','comment_num',
        //'listener_num','like_num','duration','accuent','subtitle',
        //'created_at','url','is_audio','lyric','lyric_aligin','lyric_text'
        $user = User::query()->select('id')->where('openid',$request->openid)->first();
        return [
            'data'=>[
                $this->collection,

            'is_lock'=>$this->isLock($this->id,$this->lockList,$user->id)
        ]];
    }

}
